﻿using Microsoft.Extensions.Logging;
using Sayook.Framework.DbCore.DbConnection;

namespace Sayook.Framework.DbCore.DbContext
{
    /// <summary>
    /// 通用访问数据库
    /// </summary>
    public class CommonDbContext<T> : BaseDbContext<T> where T : DbModelBase
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="connProvider">数据库连接</param>
        /// <param name="logger">日志</param>
        public CommonDbContext(IDbConnectionProvider connProvider, ILogger<CommonDbContext<T>> logger = null) : base(connProvider, logger) { }

        /// <summary>
        /// 获取数据库连接字符串
        /// </summary>
        /// <returns></returns>
        protected override string GetDbConnectionString()
        {
            //return "Database=ezp-union-busi;Data Source=192.168.12.41;User Id=ezwrite;Password=33KlsXareQbsbrfhq2eJ";
            return "server=127.0.0.1;userid=root;pwd=123456;database=sayook_framework;sslmode=none;Charset=utf8";
            //return @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=sayook.a;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
        }
    }

    /// <summary>
    /// 事务操作
    /// </summary>
    public class TranDbContext : TransactionDbContext
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="connProvider">数据库连接</param>
        /// <param name="logger">日志</param>
        public TranDbContext(IDbConnectionProvider connProvider, ILogger<TranDbContext> logger = null) : base(connProvider, logger) { }

        /// <summary>
        /// 获取数据库连接字符串
        /// </summary>
        /// <returns></returns>
        protected override string GetDbConnectionString()
        {
            //return "Database=ezp-union-busi;Data Source=192.168.12.41;User Id=ezwrite;Password=33KlsXareQbsbrfhq2eJ";
            return @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=sayook.a;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
        }
    }
}